home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 123 / MacAddict_123_2006_11.iso / Software / Internet & Communication / Sandvox 1.0.4.dmg / Sandvox.app / Contents / Resources / documentJavascript.txt < prev    next >
Text File  |  2006-08-04  |  2KB  |  64 lines

  1. // Based on some code fragments at:
  2. // http://www.codecomments.com/JScript/message294790.html
  3. // Use like this: boundsOfObject(document.getElementById("k-26FF13A42F7911D9B573"))
  4.  
  5. function boundsOfObject(aElm)
  6. {
  7.     if (!aElm) return false;
  8.     var x = aElm.offsetLeft;
  9.     var y = aElm.offsetTop;
  10.     var w = aElm.offsetWidth;
  11.     var h = aElm.offsetHeight;
  12.  
  13.     // WHEN DO I NEED TO, OR NOT NEED TO, TRAVERSE THE PARENTS....
  14.     
  15.     var lParent = aElm.parentNode;
  16.     var log = aElm + " : " + x + "," + y + " ... ";
  17.     
  18.     while (lParent && typeof lParent.offsetLeft != "undefined") {
  19.         
  20.         log = log + " parent : " + lParent + " : " + lParent.offsetLeft + ", " + lParent.offsetTop + "; ";
  21.         x += lParent.offsetLeft;
  22.         y += lParent.offsetTop;
  23.         lParent = lParent.offsetParent;
  24.     }
  25.  
  26.     return x + "," + y + "," + w + "," + h + " " + log;
  27. }
  28.  
  29. // Get border of element and set to special highlighted state
  30. function activateHilite(aElm)
  31. {
  32.     if (!aElm) return;
  33.     aElm.style.border = '2px ridge #6badef';
  34.     aElm.style.margin = '-2px';
  35. }
  36.  
  37. // Take out border, de-hiliting.
  38. function deactivateHilite(aElm)
  39. {
  40.     if (!aElm) return;
  41.     aElm.style.border = 'none';
  42.     aElm.style.margin = '0';
  43. }
  44.  
  45. // Based on code fragments at:
  46. // http://www.codelifter.com/main/javascript/capturemouseposition1.html
  47. // Returns the scroll position (relative to top,left)
  48.  
  49. function scrollOffset()
  50. {
  51.     var dx = document.body.scrollLeft;
  52.     var dy = document.body.scrollTop;
  53.     return dx + "," + dy;
  54. }
  55.  
  56. function viewSize()
  57. {
  58.     var x = document.body.clientWidth;
  59.     var y = document.body.clientHeight;
  60.     return x + "," + y;
  61. }
  62.  
  63. // Mouse position: see
  64. // http://evolt.org/article/Mission_Impossible_mouse_position/17/23335/?format=print